package com.zxj.netty.component;

import io.netty.channel.ChannelFuture;
import org.springframework.util.CollectionUtils;

import java.util.List;

// 负载均衡选择器模板
public abstract class AbsLoadBalance implements LoadBalanceService {
    @Override
    public ChannelFuture selectChannel(List<ChannelFuture> serviceRepos) {
        if (CollectionUtils.isEmpty(serviceRepos)) {
            return null;
        }

        if (serviceRepos.size() == 1) {
            return serviceRepos.get(0);
        }

        return doSelect(serviceRepos);
    }

    protected abstract ChannelFuture doSelect(List<ChannelFuture> serviceRepos);
}
